package com.book.config;

import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.request.AlipayTradePagePayRequest;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author SuperYu  2024/8/5
 */

@Configuration
public class MyMvcConfig implements WebMvcConfigurer {


    @Bean
    public AlipayTradePagePayRequest alipayTradePagePayRequest(AlipayConfig alipayConfig){
        AlipayTradePagePayRequest alipayRequest = new AlipayTradePagePayRequest();
        alipayRequest.setReturnUrl(alipayConfig.getReturn_url());
        alipayRequest.setNotifyUrl(alipayConfig.getNotify_url());
        return alipayRequest;
    }

    @Bean
    public AlipayClient alipayClient(AlipayConfig alipayConfig){
        return new DefaultAlipayClient(alipayConfig.getGatewayUrl(), alipayConfig.getApp_id(),
                alipayConfig.getMerchant_private_key(), "json", alipayConfig.getCharset(),
                alipayConfig.getAlipay_public_key(), alipayConfig.getSign_type());
    }

}
